package org.zjx.analysis.window;

import lombok.Getter;
import org.zjx.analysis.BaseAnalysis;
import org.zjx.analysis.inventor.PropAnalysis;
import org.zjx.core.IWindow;
import org.zjx.util.ImageUtil;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.List;

public class InventorAnalysis extends BaseAnalysis {

    public enum OpenSlotType{
        INVENTORY,  //道具栏
        EXTENDED_INVENTORY, //行囊栏
        QUEST_ITEMS  //任务栏
    }

    @Getter
    private OpenSlotType openSlotType = OpenSlotType.INVENTORY;
    private PropAnalysis propAnalysis;
    @Getter
    private List<BufferedImage> items;

    public InventorAnalysis(IWindow window, BufferedImage screenshot) {
        super(window, screenshot);
    }

    @Override
    protected void analysis() {
        this.openSlotType = checkOpenSlot();
        this.items = checkItemImage();
    }

    //检查栏位选中状态
    private OpenSlotType checkOpenSlot(){
        if (haveImage(imageMap.get("道具按钮-选中"))){
            return OpenSlotType.INVENTORY;
        }else if (haveImage(imageMap.get("行囊按钮-选中"))){
            return OpenSlotType.EXTENDED_INVENTORY;
        }else if (haveImage(imageMap.get("任务按钮-选中"))){
            return OpenSlotType.EXTENDED_INVENTORY;
        }
        return OpenSlotType.INVENTORY;
    }

    //检查道具栏内容
    private List<BufferedImage> checkItemImage(){
        BufferedImage contentImage = getSpecifiedAreaImage(areaMap.get("道具栏").getRectangle());
        propAnalysis = new PropAnalysis(contentImage);
        return  propAnalysis.getItemImages();
    }

    public Rectangle getItemIndexArea(int index){
        Rectangle itemsArea = conversion(windowArea,areaMap.get("道具栏").getRectangle());
        return conversion(itemsArea,propAnalysis.getIndexArea(index));
    }

    @Override
    protected void initResources() {
        areaMap.put("道具栏", new ResolutionArea(ImageUtil.createRect(252, 57, 507, 261)));
        areaMap.put("现金", new ResolutionArea(ImageUtil.createRect(302, 273, 459, 290)));

        imageMap.put("关闭按钮", new ResolutionImage(ImageUtil.createRect(519, 6, 528, 15),
                ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAA+ElEQVR4XmNYtfPq/4Vrz/23cy/7r2OS8F/bGIGNbTL+T5y9939B1YL/DCBFBy58+L9s68X/Vs4FKIrmrzoFluuZtvM/g71nJVgRSGDplov/TW2zUBTNWnrsv6Fl2n8GU4eC//aeFXDFSzad+79g9Wkwe+6KU/+tXEv+m9rnQRSaOuSjKAYrWglVBJQDYbhCW48ysKdgCkHOsHIq+K9nkfpfH2Y1siKQdUs2n4c7A+RmkOcYbD3K4YrmrDgJdjhIcunmC3CTLRyBbpyy4DBE0fITYEUg3QaWGShuBhnEUFi99H/nxO1wRSAM8iXI3dYuReBgWrD6zH8AIAT/R8hWG/MAAAAASUVORK5CYII=")
        ));

        imageMap.put("道具按钮-选中", new ResolutionImage(ImageUtil.createRect(261, 30, 334, 49),
                ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAAEoAAAAUCAYAAAAqVKv2AAADu0lEQVR4Xu2YWUwTURRAmxijgpYqCKiIC4i0UlAQLG4gGkTBFkVbZd8kLajFKti4YEHRSDSixOAaTYQIX25xX6J+IAkkCArqh0JCTNyiotEvyHXum3SgfYMSO+MP3OQkc+979728k5l2WomHMhTcXGQQ5+4FpmkKOOgfAocVcwc16ABdoBN0g44k45ydSWHXlGBIGO0LIcO8h2BAF+gE3aAjiVXSouE+Q/BglSXBW2yDdAZEMsUhaJJd/MhjKMHncdkIeoKQxMiUVK326FmIGunH5XvWGaBIl0fNS5JHcWN84Fha4HKqTyhiRvqQzywJfnihKDHBeFBzjctXSOWkdu1UNcnXeoWS/GJphU1ftJMfqQ8ktFNU1L5CgKLQ0X8RtUuTRQ6jdguyOx5/XCqrJH0a99kkP27cC+ZVGbxYtAYyRz9PTe0rBLGj+ohCa/8LtUwBqX6LYdtSHQGjlhGD15vCNaCbHMrNTfBgRQ0k8lRqai8hWOXk2ysKrYlFISPgx5dv8PndezBHJ8LqsQr7M9rEnfO1XK/WkxVVe+gEnDAW8XLSVEzmbAlXU3sLQbxzH1FoTSxSps6D6n3l5DAtj+shWx5JrnODY8h1X9qfv4I3z1q53vUT5rD2mOjp7uanp4eMG+erqb2FwEYUJmLTVtdIyFGwovqLt82tXE/iRFZUleUIHNtYwEuF3kzmmBhR9nsKAb54cqIwEZuXjCTEMIsVZT+ONN17QkRZ85RJvXfU32L7AjW1nhBox8zoFYWJ2Lx62kjIC1hif0abaG9uI/PTGEllOj2pVeaaoSQulZfS+Awy55zJAulewdS+joIv45woTMTGKmqLkhWVNNafmvPiUR10MKLw+nr5GU7eQOPu6SpqTUdJk83sFYWv6WLT2foavn34BFkT//yVX3/5JtVbGpcCP792QY53CFfbLF8EH9s7oTKngJovFCgp21XOisLXc0ywKBZ7I9ZwIhqu3oaDzCNTvsFAcUiTDunMnWbt26mKhTeNzaSv5f4TmzUzXBXQdOshty722+/rKOjFMF4BlWEa9kcxgkUxuGDcTQ7y6HwNFEeugV9d37nD9RcNV25BdWEJl5/KNlHrWjH5L4QO5pUCA3vsx/8VFITgjURE4V8ImBg9A7hBIdk6PQyKwmJsankTAsGiWgkHohJ4yZ86F3bMWgynM/Op9fpjf0Q82cu+7gj4F8uN2ExI9gkCiZtUSi7wOcQBFDbYQQ94F6EkvVIF6Egic/cGVycnIss6OEQmcYFO0A06+g1PGtEooAWbvwAAAABJRU5ErkJggg==")
        ));

        imageMap.put("行囊按钮-选中", new ResolutionImage(ImageUtil.createRect(342, 30, 415, 49),
                ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAAEoAAAAUCAYAAAAqVKv2AAADxElEQVR4Xu2YfUxNYRjA72aGLtWUZBKtkpo+VmrZGJJlK24fKs1F3ZjLHaakyEdSTENrLZlQy9yMoUzrarUarQ8hlmH5KMlokbRl/sge93nyns49J/Nx7/FPPdtv932e55z33fvbOWfnHtl0d1+wtrCEEBs7SHBwg2PzfOCE24JRDTpAF+gE3aAj2VS5nAqps70hYrIT+IyzH0MPukAn6AYdyZikxeMdxxgBJkuGl1iMuTMs1RfHEKO0mEu3oQzvx8AJ4gNMTULQejgYrRHV/5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eXr48xcT8qWpHns2hPCLSbtvWtpo8bzV7ncWyBpSYDBKQqv5xggVIpK4RmDcn2uWWRj7M1b7dx8qUPMdmUVUa4g0DW3NDGN7l66zq5rEx7kyPK1Y6g4KFa8BnWuspZb11vgZdlAI9XGpDr/KAYIlaIq3XmirEEx7OefarNwO9l0cR5ZfXm1+H2nyhwePVRJWAK3rjdAEMBBYqLwLwQMVg4eIzblxjosgvblWLn8T+zOXEp2QwKXg2LtaCqLMVFlsoVsI8ZxfTnAv1gumPPIoosg1QC1mn3AfYgGhP3vwANOESQVhccRHKk02kAK8PFhslzNbvKYCziBGzj6CWBIdzmTQtPBAAAAAElFTkSuQmCC")
        ));

        imageMap.put("行囊切换按钮", new ResolutionImage(ImageUtil.createRect(504, 30, 523, 49),
                ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABbElEQVR4Xr2UMUvDQBTH7zO4KYiDi4NDxrgFrBCkQwbBDi1kqJBBIaPjDR0CDhakNGMQ56KLiFlEHYRs1kGcihVBinTwAzzzv9pAexdyUfDBb3r/97vjQh5bNDZoZX2LbJeT3zonHt5QED1ogSxmMAsHXGx5zSLHC8hDwwvJqgVk7uiBLGYwCwdczK5zsvcjKVwWOOBiltsms9aWAqVJHXClwlBu/hK4mNWEkGvRu07o6WVI280jqQfgmggdrkV81yfU4G1Ezt6x1FcKO6cx9a4SJRBN63P8RQ2/Wyx8/xhnQ0WFAwqFf+F/hHgb3cLzqIVVntE46M5IB8MR9S4TJZ0onplVCsGud5J9nPi2L/XzyIRG9VBis96ix+dXOru4l3p5TISuWlgWcUP8eubPupoPlEX8z6mLGRVPbIn5QFmEI3UxbFrD9sV1xSmKcB7ITrcMHHCxhaVVsWmNii+ujJPwuFqIXRqIWTjg+gZHD5W7iz7z+wAAAABJRU5ErkJggg==")
        ));
    }

    @Override
    public Rectangle closeArea() {
        return null;
    }

    @Override
    public Rectangle getOriginBounds() {
        return ImageUtil.createRect(132, 133, 666, 463);
    }

    @Override
    public Rectangle getRefImageArea() {
        return ImageUtil.createRect(239, 3, 294, 16);
    }

    @Override
    public BufferedImage getRefImage() {
        return ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAADgAAAAOCAYAAAB6pd+uAAAEhElEQVR4Xp1Wj1NTRxDOn9UZZlpB7WhRBEoxUBVrRcQJhaFNBXEEqiiBMgRolfAbFFLKQ4ggktACLRSkYJAfIbQIhRLA0FEBdWSmtdu3e7njvfCC2G/m42739vb2u70H6N4JL4VgfQXgqGRD6xgERVqEnZZrh3STY1tcVKKVrX3tUNPEiGt6QyOLj/Ltk8ek7DaKI5/C759f+JVUrGUV/giZMrft8VGHPxD2n2dEgndjysnXbHeRffBUDdmVjSOqA4OiLeTfDUJP16mKREidkzTvHpz1i1YDY1Kvdvi734jkrHYmMPUy2xwSU+kXoo1ayUlC952oIju/vA9SrtzVZFq+nWLijJIQ983N++R7/2Q1u6ijZRBxrl6Te+UzlBez5N2AtY1X8GydkYPbyPXnmxD0YdlWB5V8L7ocjibegqSLrURE/W0nJKS3QtznEhyMqxGxoT6Bu0G8T+D5HHaZeTd6YY9sK4nrfORzfyIejHtgYGSeyIHzvmFGxL7YKiYwIf17Urz65CUkZthI4E6wdbmFQEyCuNnshEK5i1osquynGBSIBdY2jUCF9VdIybxDfrykf17/K/Jroal9HMLkbuPonFiCxeU1QY4/l9YER13L0HzPBaGflIEuIq4MqhoGKWh0YhH0Z1jRcYY6muvlZ0KU57Pzf8HM3CrsCTcTQ2OviwOwSC2+9hXPBSo7cd+5AMEflYJFfrLVjcMqIvqG/qC5QX5J0t1x8o2MLcLK6gYRxbR3TUKbfQIWFp/Cined+HDSQ7FjLg/oeLHjU0tELjAQtARW3PoFrhXZGUu6VTR920MxSoGOXjf5jpywiFxaT9Eof8PctjlcMOFeJv9PAzNg75miebV1kM5FoI/7px95oX9oNrBAcbCCQ855TYG7QXxqPe2xdbJOIPzzK4kwZrcIOySyCGLPVoPUNgpTv6+IHMasFjDIn9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